﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using SimpleData.Infrastructure.Plugins;
using SimpleData.Infrastructure.Serialization;
using SimpleData.ObjectModel.Design;
using System.Diagnostics.Contracts;
using SimpleData.Infrastructure.Provider;

namespace SimpleData.ObjectModel.Internals
{

	internal sealed class RuleBuilderProvider : ProviderBase<RuleName, IRuleBuilderFactory>
	{

		/// <summary>
		/// 
		/// </summary>
		/// <param name="plugContainer"></param>
		public RuleBuilderProvider( Plug plugContainer )
			: base( plugContainer )
		{
			this.AssemblyProbe.Add( Assembly.GetExecutingAssembly(), "Factory" );
		}
	}

	internal static class RuleBuilderProviderExtensions
	{
		public static IRuleBuilder Create( this IProvider<RuleName, IRuleBuilderFactory> provider, Rule data )
		{
			Contract.Requires<ArgumentNullException>( provider != null, "provider" );

			var factory = provider.Create( data.Name );
			Contract.Assert( factory != null, String.Format( "A factory para a regra \"{0}\" não foi encontrada.", data.Name ) );

			return factory.CreateRuleBuilder( data );
		}
	}

	/// <summary>
	/// 
	/// </summary>
	//internal sealed class RuleBuilderProvider : ProviderBase<Rule, IRuleBuilder> //: IRuleBuilderFactory
	//{

	//    /// <summary>
	//    /// 
	//    /// </summary>
	//    /// <param name="plugContainer"></param>
	//    public RuleBuilderProvider( Plug plugContainer )
	//        : base( plugContainer )
	//    {
	//        this.AssemblyProbe.Add( Assembly.GetExecutingAssembly(), "Builder" );
	//    }
	
	 
	//    public override IRuleBuilder Create( Rule data )
	//    {
	//        var builder = base.Create( data );
	//        if ( builder != null )
	//            builder.Init( data );

	//        return builder;
	//    }

	//    protected override IDataObjectName GetNameFrom( Rule settings )
	//    {
	//        return settings.Name;
	//    }
	//}
}
